<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="button" value="0" id="btn1">
<input type="button" value="0" id="btn2">
<script>
    var btn1 = document.getElementById('btn1');
    var btn2 = document.getElementById('btn2');
    function foo(){
        var i=0;
        return function(){
            i++;
            this.value=i;
        }
    }

    btn1.onclick = foo();
    btn2.onclick = foo();
</script>
</body>
</html>